home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / include / scribus-ng / loadsaveplugin.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-12-10  |  9.4 KB  |  233 lines

  1. /*
  2. For general Scribus (>=1.3.2) copyright and licensing information please refer
  3. to the COPYING file provided with the program. Following this notice may exist
  4. a copyright and/or license notice that predates the release of Scribus 1.3.2
  5. for which a new license (GPL+exception) is in place.
  6. */
  7. #ifndef SCRIBUS_LOADSAVEPLUGIN_H
  8. #define SCRIBUS_LOADSAVEPLUGIN_H
  9.  
  10. #include "scplugin.h"
  11.  
  12. #include <QString>
  13. #include <QRegExp>
  14. #include <QIODevice>
  15. #include <QProgressBar>
  16. #include <QStringList>
  17. #include <QList>
  18.  
  19. class FileFormat;
  20. //TODO REmove includes one day
  21. //class ScribusDoc;
  22. //class ScribusView;
  23. #include "scfonts.h"
  24. #include "scribusdoc.h"
  25. #include "scribusview.h"
  26.  
  27. /*!
  28.  * @brief Superclass for all file import/export/load/save plugins
  29.  *
  30.  * This class provides the interface common to all file load/save/import/export
  31.  * plugins. It provides the facilities for discovering what format(s) a plugin
  32.  * supports, how they should be identified, etc.
  33.  */
  34. class SCRIBUS_API LoadSavePlugin : public ScPlugin
  35. {
  36.     Q_OBJECT
  37.  
  38.     public:
  39.         // Construct a plugin instance.
  40.         LoadSavePlugin();
  41.         ~LoadSavePlugin();
  42.  
  43.         enum loadFlags
  44.         {
  45.             lfCreateDoc = 1,
  46.             lfUseCurrentPage = 2,
  47.             lfInsertPage = 4,
  48.             lfInteractive = 8,
  49.             lfScripted = 16
  50.         };
  51.  
  52.         // Static functions:
  53.  
  54.         // Return a list of format descriptions suitable for use with
  55.         // QFileDialog.  You can convert it to QString form with
  56.         // fileDialogSaveFilter().join(";;")
  57.         static const QStringList fileDialogLoadFilter();
  58.  
  59.         // Same deal but for save
  60.         static const QStringList fileDialogSaveFilter();
  61.  
  62.         // Get the highest priority format of a given id, or 0 if
  63.         // not found / not available.
  64.         static const FileFormat * getFormatById(const int id);
  65.  
  66.         // Non-static members implemented by plugins:
  67.         //
  68.         // Load the requested format from the specified path.
  69.         // Default implementation always reports failure.
  70.         virtual bool loadFile(const QString & fileName, const FileFormat & fmt, int flags, int index = 0);
  71.  
  72.         // Save the requested format to the requested path.
  73.         virtual bool saveFile(const QString & fileName, const FileFormat & fmt);
  74.  
  75.         // Return last file saved, this may be the last fileName argument passed to saveFile(),
  76.         // a temporary file name or an empty string if last call to saveFile() could not create
  77.         // a valid file
  78.         virtual const QString& lastSavedFile(void);
  79.  
  80.         // Examine the passed file and test to see whether it appears to be
  81.         // loadable with this plugin. This test must be quick and simple.
  82.         // It need not verify a file, just confirm that it looks like a supported
  83.         // file type (eg "XML doc with root element SCRIBUSXML and version 1.3.1").
  84.         // All plugins must implement this method.
  85.         virtual bool fileSupported(QIODevice* file, const QString & fileName=QString::null) const = 0;
  86.         
  87.         // Return a list of all formats supported by all currently loaded and
  88.         // active plugins. This list is sorted in a very specific order:
  89.         // First, by descending order of `id', then descending order of priority.
  90.         static const QList<FileFormat> & supportedFormats();
  91.         
  92.         virtual void setupTargets(ScribusDoc *targetDoc, ScribusView* targetView, ScribusMainWindow* targetMW, QProgressBar* targetMWPRogressBar, SCFonts* targetAvailableFonts);
  93.         virtual void getReplacedFontData(bool & getNewReplacement, QMap<QString,QString> &getReplacedFonts, QList<ScFace> &getDummyScFaces);
  94.         virtual bool loadPage(const QString & fileName, int pageNumber, bool Mpage, QString renamedPageName=QString::null);
  95.         virtual bool readStyles(const QString& fileName, ScribusDoc* doc, StyleSet<ParagraphStyle> &docParagraphStyles);
  96.         virtual bool readCharStyles(const QString& fileName, ScribusDoc* doc, StyleSet<CharStyle> &docCharStyles);
  97.         virtual bool readLineStyles(const QString& fileName, QMap<QString,multiLine> *Sty);
  98.         virtual bool readColors(const QString& fileName, ColorList & colors);
  99.         virtual bool readPageCount(const QString& fileName, int *num1, int *num2, QStringList & masterPageNames);
  100.         
  101.     protected:
  102.  
  103.         /// Check a loadFlags combination
  104.         virtual bool checkFlags(int flags);
  105.  
  106.         /// Register the passed format so it can be used by the app
  107.         void registerFormat(const FileFormat & fmt);
  108.  
  109.         /// Unregister the format with format ID `id' that references by the calling plugin.
  110.         void unregisterFormat(unsigned int id);
  111.  
  112.         /// Unregister all formats owned by the calling plugin
  113.         void unregisterAll();
  114.  
  115.         // Set standard message for file read errors
  116.         virtual void setFileReadError();
  117.  
  118.         // Set standard message for dom style errors with line and column
  119.         virtual void setDomParsingError(const QString& msg, int line, int column);
  120.         
  121.         ScribusDoc*        m_Doc;
  122.         ScribusView*       m_View; //For 1.2.x loader at the moment
  123.         ScribusMainWindow* m_ScMW; //For plugins when required
  124.         QProgressBar*      m_mwProgressBar;
  125.         SCFonts*           m_AvailableFonts;
  126.         QString            m_lastSavedFile;
  127.  
  128.     private:
  129.         // A list of all supported formats. This is maintained by plugins
  130.         // using the protected `registerFormat(...)', `unregisterFormat(...)'
  131.         // and `unregisterAll(...)' methods. This is sorted in a very specific
  132.         // order - ascending ID, then descending priority.
  133.         static QList<FileFormat> formats;
  134.  
  135.         // Return an iterator referencing the first format structure named `name'.
  136.         // If specified, only return formats implmented by `plug'.
  137.         // If `start' is specified, start searching at this iterator rather than the
  138.         // start of the list.
  139.         // The end iterator is returned if no match was found.
  140.         // Note that due to the sort order maintained in `formats', the first
  141.         // iterator returned by this method will always be to the highest
  142.         // priority format of the required ID, and each subsequent call will
  143.         // return the next lowest priority format.
  144.         static QList<FileFormat>::iterator findFormat(unsigned int id,
  145.                 LoadSavePlugin* plug = 0,
  146.                 QList<FileFormat>::iterator it = formats.begin());
  147.                 
  148.         static QList<FileFormat>::iterator findFormat(const QString& extension,
  149.                 LoadSavePlugin* plug = 0,
  150.                 QList<FileFormat>::iterator it = formats.begin());
  151.  
  152.         // Print out a format list for debugging purposes
  153.         static void printFormatList();
  154.  
  155.         // Base implementation for fileDialogLoadFilter and fileDialogSaveFilter
  156.         static const QStringList getDialogFilter(bool forLoad);
  157. };
  158.  
  159.  
  160.  
  161. // Info on each supported format. A plugin must register a
  162. // FileFormat structure for every format it knows how to load or
  163. // save. If it both loads and saves a given format, one structure must
  164. // be registered for load and one for save.
  165. // Plugins must unregister formats when being unloaded to ensure that
  166. // no attempt is made to load a file using a plugin that's no longer
  167. // available.
  168. //
  169. // This class also provides methods to ask the implementation to load / save a
  170. // file in this format.
  171. class SCRIBUS_API FileFormat
  172. {
  173.     public:
  174.         // Default ctor to make QValueList happy
  175.         FileFormat() : load(false), save(false), plug(0) {}
  176.         // Standard ctor that sets up a valid FileFormat
  177.         FileFormat(LoadSavePlugin * plug) : load(false), save(false), plug(plug) {}
  178.         // Load a file with this format
  179.         bool loadFile(const QString & fileName, int flags, int index = 0) const;
  180.         // Save a file with this format
  181.         bool saveFile(const QString & fileName) const;
  182.         // Get last saved file
  183.         QString lastSavedFile(void) const;
  184.         
  185.         void setupTargets(ScribusDoc *targetDoc, ScribusView* targetView, ScribusMainWindow* targetMW, QProgressBar* targetMWPRogressBar, SCFonts* targetAvailableFonts) const;
  186.         void getReplacedFontData(bool & getNewReplacement, QMap<QString,QString> &getReplacedFonts, QList<ScFace> &getDummyScFaces) const;
  187.         bool loadPage(const QString & fileName, int pageNumber, bool Mpage, QString renamedPageName=QString::null) const;
  188.         bool readStyles(const QString& fileName, ScribusDoc* doc, StyleSet<ParagraphStyle> &docParagraphStyles) const;
  189.         bool readCharStyles(const QString& fileName, ScribusDoc* doc, StyleSet<CharStyle> &docCharStyles) const;
  190.         bool readLineStyles(const QString& fileName, QMap<QString,multiLine> *Sty) const;
  191.         bool readColors(const QString& fileName, ColorList & colors) const;
  192.         bool readPageCount(const QString& fileName, int *num1, int *num2, QStringList & masterPageNames) const;
  193.         //
  194.         // Data members
  195.         //
  196.         // An integer ID code used to idenfify formats. Should be unique
  197.         // across all FileFormat structures except where they implement
  198.         // support for the same file format, eg sla 1.2.x, sla 1.3.x and
  199.         // "new format" SLA should all have equal IDs (with different
  200.         // priorities to control what order they're tried in when a user
  201.         // tries to open a file).
  202.         // Note that dialog box options are sorted in descending `id' order.
  203.         uint formatId;
  204.         // The human-readable, translated name of this file format.
  205.         QString trName;
  206.         // A filter in the format used by QFileDialog that should be used to
  207.         // select for this format.
  208.         QString filter;
  209.         // Regexp to match filenames for this format
  210.         QRegExp nameMatch;
  211.         // MIME type(s) that should be matched by this format.
  212.         QStringList mimeTypes;
  213.         // Can we load it?
  214.         bool load;
  215.         // Can we save it?
  216.         bool save;
  217.         // Priority of this format from 0 (lowest, tried last) to
  218.         // 255 (highest, tried first). 64-128 recommended in general.
  219.         // Priority controls the order options are displayed in when a file
  220.         // of a given type is selected in a dialog, and controls the order
  221.         // loaders are tried in when multiple plugins support the same file
  222.         // type.
  223.         unsigned short int priority;
  224.         // For convenience, a pointer back to the plugin to use to open
  225.         // this format.
  226.         LoadSavePlugin * plug;
  227. //        LoadSavePlugin * const plug;
  228. };
  229.  
  230.  
  231.  
  232. #endif
  233.